<!-- 订单交易处理 -->
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="display: flex;justify-content: space-between;">
			<div>
				<p class="text">订单交易处理</p>
			</div>
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.name" placeholder="手机号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getUsers">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="List" highlight-current-row v-loading="loading" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column type="expand">
			  <template slot-scope="props">
			    <el-form label-position="left" inline class="demo-table-expand">
					<el-form-item label="订单 ID:">
						<span>{{ props.row.orderId }}</span>
					</el-form-item>
					<el-form-item label="卖家 ID:">
						<span>{{ props.row.userId }}</span>
					</el-form-item>
			    </el-form>
			  </template>
			</el-table-column>
			<el-table-column prop="num" align="center" label="数量" width="60"></el-table-column>
			<el-table-column prop="price" align="center" label="价格"></el-table-column>
			<el-table-column prop="phone" align="center" label="出售人手机号" width="120"></el-table-column>
			<el-table-column prop="nickName" align="center" label="姓名" width="140"></el-table-column>
			<el-table-column prop="starLevel" align="center" label="星级"></el-table-column>
			<el-table-column prop="rate" align="center" label="手续费" ></el-table-column>
			<el-table-column prop="dirctNum" align="center" label="直推人数"></el-table-column>
			<el-table-column prop="isRealCount" align="center" label="实名人数"></el-table-column>
			<el-table-column prop="buyerId" align="center" label="购买者ID" width="100"></el-table-column>
			<el-table-column prop="buyerName" align="center" label="购买者姓名" width="120"></el-table-column>
			<el-table-column prop="buyerPhone" align="center" label="购买者手机号" width="120"></el-table-column>
			<el-table-column prop="orderTime" align="center" label="时间" width="160" ></el-table-column>
			<el-table-column prop="img" align="center" label="图片" width="120">
				<template slot-scope="scope">
					 <p v-if="!scope.row.img">无图片</p>
					 <el-link v-else :underline="false" @click="Look(scope.row.img)">查看图片</el-link>
				</template>
			</el-table-column>
			<el-table-column prop="orderStatus" align="center" label="订单状态">
				<template slot-scope="scope">
					<p v-if="scope.row.orderStatus == '0'">待处理</p>
					<p v-if="scope.row.orderStatus == '1'">取消</p>
					<p v-if="scope.row.orderStatus == '2'">确认</p>
				</template>
			</el-table-column>
			<el-table-column prop="orderNo" align="center" label="订单号" width="180"></el-table-column>
			<el-table-column label="操作" align="center" width="200" >
				<template slot-scope="scope">
					<el-button size="small" type="success" icon="el-icon-edit" @click="handleEdit(2,scope.row)">确认</el-button>
					<el-button size="small" type="danger" icon="el-icon-edit" @click="handleEdit(1,scope.row)">取消</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!-- 查看图片 -->
		<el-dialog title="查看图片" :visible.sync="Lookloading" width="35%" :before-close="handleClose">
			<el-image :src="url"></el-image>
		</el-dialog>
	</section>
</template>
<script>
	import {
		getqueryOrderList,
		editqueryOrderList,
		Refreshtoken
	} from '../../../api/api';
	
	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				loading: false,
				List: [],
				sels: [],//列表选中列81560
				total: 0,
				page: 1,
				size:10,
				timer: null,
				// 查看图片
				Lookloading:false,
				url: '',
			}
		},
		mounted() {
			this.getList()
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
		},
		methods: {
			//获取列表
			getList:function(type){
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp};
				this.loading = true;
				getqueryOrderList(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.List = res.data.list;
						this.loading = false;
					}
				});
			},
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			//查看
			Look(type){
				this.Lookloading = true
				this.url = type
			},
			// 操作按钮
			handleEdit(type,row){
				if (type == '1') {
					this.$confirm('是否取消'+'订单号：'+row.orderNo+' 的订单？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp = new Date().getTime();
						var para = {token: Token,timestamp: timestamp,orderId:row.orderNo,orderStatus:type};
						editqueryOrderList(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.$message({
									type: 'success',
									message: '订单状态修改成功！！！'
								});
								this.loading = false;
								this.getList();
							}
						});
					});
				} else if(type == '2'){
					this.$confirm('是否修改'+'订单号：'+row.orderNo+' 的订单为确认状态？', '提示', {}).then(() => {
						var Token = sessionStorage.getItem('Token');
						var timestamp = new Date().getTime();
						var para = {token: Token,timestamp: timestamp,orderId:row.orderNo,orderStatus:type};
						editqueryOrderList(para).then((res) => {
							var res = res.data;
							if (res.code != 0) {
								this.$message({
									message: res.message,
									type: 'error'
								});
							} else {
								this.$message({
									type: 'success',
									message: '订单状态修改成功！！！'
								});
								this.loading = false;
								this.getList();
							}
						});
					});
				}
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			cellStyle({row, column}){
				return 'text-align:center;padding:2px;';
			},
			rowClass({row, column}){
				return 'text-align:center';
			},
			handleSizeChange(val) {
				this.size = val;
				this.getList();
			},
			handleCurrentChange(currentPage) {
				this.page = currentPage;
				this.getList();
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
				.catch(_ => {});
			},
			//条件查询
			getUsers(){
				if (this.filters.name == '') {
					this.$message({
						message: '请输入查询条件',
						type: 'error'
					});
				} else{
					var Token = sessionStorage.getItem('Token');
					var timestamp = new Date().getTime();
					var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp,phone:this.filters.name};
					getqueryOrderList(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$message({
								message: '查询成功',
								type: 'success'
							});
							this.total = res.data.total;
							this.List = res.data.list;
							this.loading = false;
						}
					});
				}
			},
		},
		
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.el-select .el-input .el-input--suffix .el-input__inner {
    width: 130px !important;
  }  
  
  .demo-table-expand {
  	display: flex;
  	flex-direction: column;
      font-size: 0;
    }
    .demo-table-expand label {
      width: 90px;
      color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
      margin-right: 0;
      margin-bottom: 0;
      width: 50%;
    }
</style>

